package com.ruoyi.common.enums;

import java.util.HashMap;
import java.util.Map;

import org.springframework.lang.Nullable;

/**
 * 请求方式
 */
public enum HttpMethod {
    /**
     * 获取资源
     */
    GET,
    /**
     * 获取资源的元信息
     */
    HEAD,
    /**
     * 创建资源
     */
    POST,
    /**
     * 更新资源
     */
    PUT,
    /**
     * 部分更新资源
     */
    PATCH,
    /**
     * 删除资源
     */
    DELETE,
    /**
     * 获取支持的通信选项
     */
    OPTIONS,
    /**
     * 回显收到的请求
     */
    TRACE;

    private static final Map<String, HttpMethod> mappings = new HashMap<>(16);

    static {
        for (HttpMethod httpMethod : values()) {
            mappings.put(httpMethod.name(), httpMethod);
        }
    }

    @Nullable
    public static HttpMethod resolve(@Nullable String method) {
        return (method != null ? mappings.get(method) : null);
    }

    public boolean matches(String method) {
        return (this == resolve(method));
    }
}
